
package com.my.xadmin.security.service.impl;

import com.my.framework.page.Page;
import com.my.framework.page.PageUtils;
import com.my.framework.shiro.ShiroDbRealm;
import com.my.xadmin.security.entity.Config;
import com.my.xadmin.security.repository.ConfigDAO;
import com.my.xadmin.security.service.ConfigService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;
@Service
@Transactional
public class ConfigServiceImpl implements ConfigService {
	
	@Autowired
	private ConfigDAO configDAO;
	
	@Autowired(required = false)
	private ShiroDbRealm shiroRealm;
	
	@Override
	public void save(Config config){
		configDAO.save(config);
	}

	@Override
	public Config get(Long id) {
		return configDAO.findOne(id);
	}
	
	@Override
	public List<Config> findAll(Page page) {
		org.springframework.data.domain.Page<Config> springDataPage = configDAO.findAll(PageUtils.createPageable(page));
		page.setTotalCount(springDataPage.getTotalElements());
		return springDataPage.getContent();
	}

	/**   
	 */
	public void update(Config config) {
		configDAO.save(config);
	}

	/**   
	 * @param id  
	 */
	public void delete(Long id) {
		configDAO.delete(id);
	}

	/**
	 * @param page
	 * @return
	 */
	public List<Config> find(String key, Page page) {
		org.springframework.data.domain.Page<Config> springDataPage = 
				(org.springframework.data.domain.Page<Config>)configDAO.findByKeyContaining(key, PageUtils.createPageable(page));
		page.setTotalCount(springDataPage.getTotalElements());
		return springDataPage.getContent();
	}

	@Override
	public List<Config> findByStatus(String status) {
		return configDAO.findByStatus(status);
	}

	@Override
	public List<Config> findByKey(String key) {
		return configDAO.findByKey(key);
	}
	
	@Override
	public List<Config> findByKeyAndId(String key, Long id) {
		return configDAO.findByKeyAndId(key,id);
	}

	@Override
	public String findValueByKey(String key) {
		return configDAO.findValueBykey(key);
	}

	@Override
	public List<Object[]> findNationCode() {
		return configDAO.findNationCode();
	}

}
